# building.py
import numpy as np
from utils import check_connectivity

class Building:
    def __init__(self, num_floors):
        self.num_floors = num_floors
        self.floors = [self.generate_floor(i) for i in range(num_floors)]
        self.stairs = self.define_stairs()
        self.exits = self.define_exits()

    def generate_floor(self, floor_number):
        # 生成固定的楼层布局
        layout = np.zeros((20, 20), dtype=int)
        # 设置边缘为墙体
        layout[0, :] = layout[-1, :] = layout[:, 0] = layout[:, -1] = 1
        # 设置走廊
        layout[:, 10] = 0
        layout[10, :] = 0
        # 设置房间
        for i in range(2, 18, 4):
            for j in range(2, 18, 4):
                layout[i:i+2, j:j+2] = 1
        return layout

    def define_stairs(self):
        # 定义每层的楼梯位置
        stairs = {
            0: [(1, 1), (18, 18)],
            1: [(1, 1), (18, 18)],
            2: [(1, 1), (18, 18)],
            3: [(1, 1), (18, 18)],
            4: [(1, 1), (18, 18)],
            5: [(1, 1), (18, 18)],
        }
        return stairs

    def define_exits(self):
        # 定义一楼的出口位置
        exits = [(0, 10), (19, 10), (10, 0), (10, 19)]
        return exits

    def is_fully_connected(self):
        # 检查所有楼层的所有可移动区域是否能通往一楼的任一出口
        return check_connectivity(self.floors, self.stairs, self.exits)
